package top.heue.utils.base.base

import android.content.Context
import android.os.Bundle
import android.view.KeyEvent
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleEventObserver
import top.heue.utils.base.helper.activity
import top.heue.utils.base.helper.inflate
import top.heue.utils.lifecycle.helper.viewModel
import top.heue.utils.log.L

open class BaseFragment : Fragment() {
    val activity by activity()

    override fun onAttach(context: Context) {
        super.onAttach(context)
        //生命周期日志
        lifecycle.addObserver(LifecycleEventObserver { _, event ->
            L.d("Life", "$this\n${event.name}")
        })
    }

    override fun onDetach() {
        super.onDetach()
        L.d("Life", "$this\nonDetach")
    }

    override fun onDestroyView() {
        super.onDestroyView()
        L.d("Life", "$this\nonDestroyView")
    }

    /** 返回是否解决*/
    open fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        return true
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        L.d("Life", "$this\nonSaveInstanceState")
    }

    override fun onViewStateRestored(savedInstanceState: Bundle?) {
        super.onViewStateRestored(savedInstanceState)
        L.d("Life", "$this\nonViewStateRestored")
    }
}